﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI;
using System.Xml;
using System.Globalization;

using System.Security.Cryptography;
namespace Servicios
{
    public class Utilidades
    {
        public static string GetHash(string _str)
        {
            string strhash = string.Empty;
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            byte[] bs = Encoding.UTF8.GetBytes(_str);
            bs = md5.ComputeHash(bs);
            StringBuilder str = new StringBuilder();
            foreach (byte b in bs)
            {
                str.Append(b.ToString("x2").ToLower());
            }
            return str.ToString();
        }

        //-----------------------------------------------------------------------------
        // Descripción      : Seleciona un valor del DropDowList
        // Parametros       : DropDownList, Valor String
        // Retorno		    : Integer
        // Observacion      : 
        // ----------------------------------------------------------------------------        
        public static int DropDownListSelectValue(ref DropDownList pddl, string pstrValor)
        {
            if (pddl.Items.IndexOf(pddl.Items.FindByValue(pstrValor)) >= 0)
            {
                pddl.SelectedItem.Selected = false;
                pddl.SelectedIndex = pddl.Items.IndexOf(pddl.Items.FindByValue(pstrValor));
                return 1;
            }
            return 0;
        }

        public static int DropDownListAnnadir(ref DropDownList pddl,
                                      string pstrValorNuevoItem, string pstrDescNuevoItem,
                                      int pintPos)
        {
            if (pintPos < 0 && pintPos >= pddl.Items.Count)
            {
                return -1;
            }
            if (pstrDescNuevoItem.Length > 0)
            {
                ListItem litem = new ListItem();
                litem.Text = pstrDescNuevoItem;
                litem.Value = pstrValorNuevoItem;
                pddl.Items.Insert(pintPos, litem);
            }
            return 0;
        }


        public static int ListBoxAnnadir(ref ListBox plb,
                                      string pstrValorNuevoItem, string pstrDescNuevoItem)
        {


            ListItem litem = new ListItem();
            litem.Text = pstrDescNuevoItem;
            litem.Value = pstrValorNuevoItem;
            plb.Items.Add(litem);
            return 0;
        }



    }
}